package cn.scnu.controller;

import cn.scnu.common.model.ResponseResult;
import cn.scnu.model.dto.*;
import cn.scnu.model.enums.KeyNameEnum;
import cn.scnu.model.query.KeyQueryParam;
import cn.scnu.service.IBaiyunProjectListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * TODO
 *
 * @author hqz
 * @className DataDashboardController
 * @createTime 2024年12月18日 14:08:00
 */
@RestController
@RequestMapping("/dataDashboard")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "可视化大屏接口")
public class DataDashboardController {
    private final IBaiyunProjectListService projectListService;

    @ApiOperation(value = "获取数字大屏可查询的所有年份")
    @GetMapping("getYears")
    public ResponseResult<List<Integer>> getYears() {
        return ResponseResult.success(projectListService.getYears());
    }

    @ApiOperation(value = "合同：获取的数量和金额，key为合同数量，value为合同金额")
    @GetMapping("getContractCountAndAmountByYear")
    public ResponseResult<BaseKeyValueDTO<Integer, Double>> getContractCountAndAmountByYear(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getContractCountAndAmountByYear(year));
    }

    @ApiOperation(value = "合同：获取一年数量的变化")
    @GetMapping("getContractCountChangeByYear")
    public ResponseResult<List<BaseKeyValueDTO<Integer, Integer>>> getContractCountChangeByYear(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getContractCountChangeByYear(year));
    }

    @ApiOperation(value = "合同：获取一年金额的变化")
    @GetMapping("getContractAmountChangeByYear")
    public ResponseResult<List<BaseKeyValueDTO<Integer, Double>>> getContractAmountChangeByYear(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getContractAmountChangeByYear(year));
    }

    @ApiOperation(value = "合同：获取各生成板块数量和金额")
    @GetMapping("getContractCountAndAmountForScbk")
    public ResponseResult<List<CountAndAmountForScbkDTO>> getContractCountAndAmountForScbk(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getContractCountAndAmountForScbk(year));
    }

    @ApiOperation(value = "合同：获取生产板块的唯一值")
    @GetMapping("getUniqueScbk")
    public ResponseResult<List<String>> getUniqueScbk(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getUniqueScbk(year));
    }

    @ApiOperation(value = "合同：获取指定生成板块下各业务类型的数量")
    @GetMapping("getContractCountForYwlx")
    public ResponseResult<List<BaseKeyValueDTO<String, Integer>>> getContractCountForYwlx(@RequestParam Integer year, @RequestParam String scbk) {
        return ResponseResult.success(projectListService.getContractCountForYwlx(year, scbk));
    }

    @ApiOperation(value = "合同：获取指定生成板块下各业务类型的金额")
    @GetMapping("getContractAmountForYwlx")
    public ResponseResult<List<BaseKeyValueDTO<String, Double>>> getContractAmountForYwlx(@RequestParam Integer year, @RequestParam String scbk) {
        return ResponseResult.success(projectListService.getContractAmountForYwlx(year, scbk));
    }

    @ApiOperation(value = "合同：获取生产板块下业务类型的唯一值")
    @GetMapping("getUniqueYwlxByScbk")
    public ResponseResult<List<String>> getUniqueYwlxByScbk(@RequestParam Integer year, @RequestParam String scbk) {
        return ResponseResult.success(projectListService.getUniqueYwlxByScbk(year, scbk));
    }

    @ApiOperation(value = "合同：获取指定生成板块下的业务类型每月的金额数量")
    @GetMapping("getContractMonthAmountForYwlxByScbk")
    public ResponseResult<List<ContractMonthAmountForYwlxByScbkDTO>> getContractMonthAmountForYwlxByScbk(@RequestParam Integer year, @RequestParam String scbk, @RequestParam String ywlx) {
        return ResponseResult.success(projectListService.getContractMonthAmountForYwlxByScbk(year, scbk, ywlx));
    }

    @ApiOperation(value = "收款：获取收款金额")
    @GetMapping("getReceiveAmount")
    public ResponseResult<Double> getReceiveAmount(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getReceiveAmount(year));
    }

    @ApiOperation(value = "收款：获取每月收款金额")
    @GetMapping("getMonthReceiveAmount")
    public ResponseResult<List<BaseKeyValueDTO<Integer, Double>>> getMonthReceiveAmount(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getMonthReceiveAmount(year));
    }

    @ApiOperation(value = "收款：获取各生产板块下的收款金额")
    @GetMapping("getReceiveAmountForScbk")
    public ResponseResult<List<BaseKeyValueDTO<String, Double>>> getReceiveAmountForScbk(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getReceiveAmountForScbk(year));
    }

    @ApiOperation(value = "收款：获取指定生产板块下各业务类型的收款金额")
    @GetMapping("getReceiveAmountForYelxByScbk")
    public ResponseResult<List<BaseKeyValueDTO<String, Double>>> getReceiveAmountForYelxByScbk(@RequestParam Integer year, @RequestParam String scbk) {
        return ResponseResult.success(projectListService.getReceiveAmountForYelxByScbk(year, scbk));
    }

    @ApiOperation(value = "收款：获取指定生产板块、业务类型下每月的收款金额")
    @GetMapping("getMonthReceiveAmountForYelxByScbk")
    public ResponseResult<List<BaseKeyValueDTO<Integer, Double>>> getMonthReceiveAmountForYelxByScbk(@RequestParam Integer year, @RequestParam String scbk, @RequestParam String ywlx) {
        return ResponseResult.success(projectListService.getMonthReceiveAmountForYelxByScbk(year, scbk, ywlx));
    }

    @ApiOperation(value = "产值：获取产值")
    @GetMapping("getProductionAmount")
    public ResponseResult<Double> getProductionAmount(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getProductionAmount(year));
    }

    @ApiOperation(value = "产值：获取每月产值")
    @GetMapping("getMonthProductionAmount")
    public ResponseResult<List<BaseKeyValueDTO<Integer, Double>>> getMonthProductionAmount(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getMonthProductionAmount(year));
    }

    @ApiOperation(value = "产值：获取获取各生产板块下的产值")
    @GetMapping("getProductionAmountForScbk")
    public ResponseResult<List<BaseKeyValueDTO<String, Double>>> getProductionAmountForScbk(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getProductionAmountForScbk(year));
    }

    @ApiOperation(value = "产值：获取指定生产板块下各业务类型的产值")
    @GetMapping("getProductionAmountForYelxByScbk")
    public ResponseResult<List<BaseKeyValueDTO<String, Double>>> getProductionAmountForYelxByScbk(@RequestParam Integer year, @RequestParam String scbk) {
        return ResponseResult.success(projectListService.getProductionAmountForYelxByScbk(year, scbk));
    }

    @ApiOperation(value = "产值：获取指定生产板块、业务类型下每月的产值")
    @GetMapping("getMonthProductionAmountForYelxByScbk")
    public ResponseResult<List<BaseKeyValueDTO<Integer, Double>>> getMonthProductionAmountForYelxByScbk(@RequestParam Integer year, @RequestParam String scbk, @RequestParam String ywlx) {
        return ResponseResult.success(projectListService.getMonthProductionAmountForYelxByScbk(year, scbk, ywlx));
    }

    @ApiOperation(value = "项目：获取项目指标")
    @GetMapping("getProjectIndex")
    public ResponseResult<DataDashProjectDTO> getProjectIndex(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getProjectIndex(year));
    }

    @ApiOperation(value = "项目：获取每月项目入案数")
    @GetMapping("getMonthProjectNum")
    public ResponseResult<List<BaseKeyValueDTO<Integer, Integer>>> getMonthProjectNum(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getMonthProjectNum(year));
    }

    @ApiOperation(value = "项目：获取每月项目出案数")
    @GetMapping("getMonthProjectCaseCount")
    public ResponseResult<List<BaseKeyValueDTO<Integer, Integer>>> getMonthProjectCaseCount(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getMonthProjectCaseCount(year));
    }

    @ApiOperation(value = "项目：获取每月项目拟收费")
    @GetMapping("getMonthProjectPlannedCharge")
    public ResponseResult<List<BaseKeyValueDTO<Integer, Double>>> getMonthProjectPlannedCharge(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getMonthProjectPlannedCharge(year));
    }

    @ApiOperation(value = "项目：获取各生成板块下入案数量和拟收费金额")
    @GetMapping("getProjectCountAndAmountForScbk")
    public ResponseResult<List<ProjectCountAndAmountForScbkDTO>> getProjectCountAndAmountForScbk(@RequestParam Integer year) {
        return ResponseResult.success(projectListService.getProjectCountAndAmountForScbk(year));
    }

    @ApiOperation(value = "项目：获取指定生产板块下各业务类型的入案数、出案数")
    @GetMapping("getProjectCountForYelxByScbk")
    public ResponseResult<List<ProjectRaAndCaDTO>> getProjectCountForYelxByScbk(@RequestParam Integer year, @RequestParam String scbk) {
        return ResponseResult.success(projectListService.getProjectCountForYelxByScbk(year, scbk));
    }

    @ApiOperation(value = "项目：获取指定生产板块下各业务类型的拟收费和已收费金额")
    @GetMapping("getProjectNsfCountForYelxByScbk")
    public ResponseResult<List<NsfAndYsfForScbkDTO>> getProjectNsfCountForYelxByScbk(@RequestParam Integer year, @RequestParam String scbk) {
        return ResponseResult.success(projectListService.getProjectNsfCountForYelxByScbk(year, scbk));
    }

    @ApiOperation(value = "镇街：获取白云区镇街的唯一值")
    @GetMapping("getUniqueZj")
    public ResponseResult<List<String>> getUniqueZj() {
        return ResponseResult.success(projectListService.getUniqueZj());
    }

    @ApiOperation(value = "镇街：根据业务环节： 【1、前期咨询/项目立项 2、地理信息数据服务 3、规划编制及专项评估 4、用地报批 5、土地供应 6、规划报建 7、规划条件核实及登记】 获取项目的入案、出案、拟收费、已收费")
    @GetMapping("getProjectIndexForYwlxAndYwhjByTown")
    public ResponseResult<List<ProjectCountAndAmountForYwlxAndYwhjDTO>> getProjectIndexForYwlxByTown(@RequestParam Integer year, @RequestParam String townName) {
        return ResponseResult.success(projectListService.getProjectIndexForYwlxByTown(year, townName));
    }

    @ApiOperation(value = "镇街：根据业务环节： 【1、前期咨询/项目立项 2、地理信息数据服务 3、规划编制及专项评估 4、用地报批 5、土地供应 6、规划报建 7、规划条件核实及登记】 获取项目的入案、出案、拟收费、已收费导出excel文件", produces = "application/octet-stream")
    @PostMapping("exportTownProjectStatsByBusinessPhase")
    public void exportTownProjectStatsByBusinessPhase(@RequestParam Integer year, @RequestParam String townName, HttpServletResponse response) {
        projectListService.exportTownProjectStatsByBusinessPhase(year, townName, response);
    }

    @ApiOperation(value = "重点：获取重点平台、重点业主、重点项目的字段名称")
    @GetMapping("getKeyNameEnum")
    public ResponseResult<KeyNameEnum[]> getKeyNameEnum() {
        return ResponseResult.success(KeyNameEnum.values());
    }


    @ApiOperation(value = "重点：依据重点平台、重点业主、重点项目的字段名获取数据")
    @PostMapping("getKeyList")
    public ResponseResult<List<ProjectDataFormDTO>> getKeyList(@RequestBody KeyQueryParam keyQueryParam) {
        return ResponseResult.success(projectListService.getKeyList(keyQueryParam));
    }

    @ApiOperation(value = "重点：依据重点平台、重点业主、重点项目的字段名导出excel文件", produces = "application/octet-stream")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyQueryParam", value = "查询参数", required = true, dataType = "KeyQueryParam")
    })
    @PostMapping("exportKeyResultExcel")
    public void exportKeyResultExcel(@RequestBody KeyQueryParam keyQueryParam, HttpServletResponse response) {
        projectListService.exportKeyResultExcel(keyQueryParam, response);
    }

    // 导入excel 文件，解析数据，存入数据库
    @ApiOperation(value = "数据覆盖：导入excel文件，解析数据，存入数据库")
    @PostMapping("importBaiyunProjectExcel")
    public ResponseResult<Integer> importBaiyunProjectExcel(@RequestParam("file") MultipartFile file) {
        return ResponseResult.success(projectListService.importBaiyunProjectExcel(file));
    }

}
